const std = @import("std");


pub const Direction = struct {
	up: bool = false,
	down: bool = false,
	left: bool = false,
	right: bool = false,


	pub fn any(self: *const Direction) bool {
		if (self.up) {
			return true;
		}
		if (self.down) {
			return true;
		}
		if (self.left) {
			return true;
		}
		if (self.right) {
			return true;
		}

		return false;
	}


	pub fn as_direction(pos_start: [2]u8, pos_end: [2]u8) Direction {
		var direction = Direction{};
		const horiz: i16 = std.math.clamp(@as(i16, pos_end[0]) - pos_start[0], -1, 1);
		const vert: i16 = std.math.clamp(@as(i16, pos_end[1]) - pos_start[1], -1, 1);

		if (horiz > 0) {
			direction.right = true;
		} else if (horiz < 0) {
			direction.left = true;
		}

		if (vert > 0) {
			direction.down = true;
		} else if (vert < 0) {
			direction.up = true;
		}

		return direction;
	}


	pub fn eq(self: *const Direction, direction: Direction) bool {
		if (self.up != direction.up) {
			return false;
		}
		if (self.down != direction.down) {
			return false;
		}
		if (self.left != direction.left) {
			return false;
		}
		if (self.right != direction.right) {
			return false;
		}

		return true;
	}
};
